package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.PageAll;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServicelmpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageAll getAllStudents(String name, Integer degree, Long clazzId, Integer page, Integer pageSize) {
        //分页查询
        PageHelper.startPage(page, pageSize);
        //数据库查询数据
        List<Student> studentList = studentMapper.getAllStudents(name, degree, clazzId);
        //强转
        Page<Student> studentPage = (Page<Student>) studentList;
        return new PageAll(studentPage.getTotal(), studentPage.getResult());
    }

    @Override
    public Student getById(Long id) {

        return studentMapper.getById(id);
    }

    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public void deleteStudent(List<Long> ids) {
        studentMapper.deleteStudent(ids);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }

    @Override
    public void updateScoreById(Long id, Integer score) {
        studentMapper.updateScoreById(id,score);
    }
}
